/******************************************************************
 * @version      : 1.0
 * @Author       : zhl
 * @Date         : 2022-12-06 14:50:32
 * @LastEditors  : zhl
 * @E-Mail       : zhll168@163.com
 * @Description  : 业务描述
 ******************************************************************/
#include <iostream>
#include "Link-APDU.h"
#include "LINK-Request.h"
#include "LINK-Response.h"
#include "CLogger.h"


#define LINK_APDU_LEN 128


Link_APDU Link_APDU::c_link_apdu; 

Link_APDU::Link_APDU(){
    // c_apdu.apdu_max_len = LINK_APDU_LEN;
    c_apdu.apdu_len = 0;
    c_apdu.apdu_tag = 0;
    // c_apdu.apdu = (uint8_t *)malloc(c_apdu.apdu_max_len);
}

Link_APDU::~Link_APDU(){
    if(NULL != c_apdu.apdu){
        free(c_apdu.apdu);
    }
}

Link_APDU& Link_APDU::getInstance(){
    return c_link_apdu;
}

APDU& Link_APDU::packet(LINK_APDU_TAG tag, LINK_REQUEST_TYPE type, uint16_t heartbeat_interval){
    // c_apdu.apdu_len = 0;
    // c_apdu.apdu_tag = tag;
    // c_apdu.apdu[0] = tag;
    // c_apdu.apdu_len++;
    // if(tag == LINK_REQUEST){
    //     c_apdu.apdu_len += LinkRequest::getInstance().packet(c_apdu.apdu, c_apdu.apdu_max_len, type, heartbeat_interval, c_apdu.apdu_len);
    // } else if(tag == LINK_RESPONSE){
    //     c_apdu.apdu_len += LinkRequest::getInstance().packet(c_apdu.apdu, c_apdu.apdu_max_len, type, heartbeat_interval, c_apdu.apdu_len);
    // } else {
    //     CLogger::getInstance()->LOG_W("未知预链接标签");
    //     c_apdu.apdu_len = 0;
    // }
    return c_apdu;
}

int Link_APDU::unpack(uint8_t* data, int& len, int start){

}